package com.uff.hmstpa.model.impl;

import com.uff.hmstpa.model.observer.AppointmentsObserver;
import com.uff.hmstpa.model.ScheduleSystem;
import com.uff.hmstpa.model.domain.entity.AbstractDoctor;
import com.uff.hmstpa.model.domain.valueobject.Appointment;
import com.uff.hmstpa.model.domain.entity.Doctor;
import com.uff.hmstpa.model.domain.valueobject.Patient;
import java.util.ArrayList;
import org.joda.time.DateTime;

public class ScheduleSystemImpl implements ScheduleSystem {

    private ArrayList<AbstractDoctor> doctors = new ArrayList();
    private AbstractDoctor selectedDoctor = null;
    private ArrayList<AppointmentsObserver> observers = new ArrayList();

    public void init() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public AbstractDoctor createDoctor(String name) {
        Doctor doctor = new Doctor();
        doctor.setName(name);
        return doctor;
    }
    
    public void addDoctor(AbstractDoctor doctor) {
        this.doctors.add(doctor);
        this.notifyObservers();
    }

    public ArrayList<AbstractDoctor> retrieveDoctors() {
        return this.doctors;
    }

    public void setSelectedDoctor(AbstractDoctor selectedDoctor) {
        this.selectedDoctor = selectedDoctor;
    }

    public AbstractDoctor getSelectedDoctor() {
        return selectedDoctor;
    }

    public void createAppointment(AbstractDoctor doctor, Patient patient, DateTime time) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void editAppointment(Appointment appointment) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void deleteAppointment(Appointment appointment) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void registerObserver(AppointmentsObserver o) {
        this.observers.add(o);
    }

    public void removeObserver(AppointmentsObserver o) {
        int index = observers.indexOf(o);
        if (index >= 0) {
            observers.remove(index);
        }
    }

    public void notifyObservers() {
        for (AppointmentsObserver observer : observers) {
            observer.update(this.doctors);
        }
    }
}
